package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {
    /**
     * 插入菜品信息
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    @Insert(value = "insert into dish " +
            "(name, category_id, price, image, description,status, create_time, update_time, " +
            "create_user, update_user) " +
            "VALUES (#{name},#{categoryId},#{price},#{image},#{description},#{status}" +
            ",#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void save(Dish dish);

    /**
     * 分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<Dish> page(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 通过id获取菜品
     * @param id
     * @return
     */
    @Select("select * from dish where id=#{id}")
    Dish getById(Long id);

    /**
     * 修改菜品信息
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 通过id删除菜品
     * @param id
     */
    @Delete("delete from dish where id=#{id}")
    void deleteBatch(Long id);

    /**
     * 通过分类id获取菜品
     * @param category
     * @return
     */
    //@Select("select * from dish where category_id=#{categoryId}")
    List<DishVO> getByCategoryId(Category category);

    /**
     * 通过菜品id获取菜品是否起售
     * @param dishIds
     * @param disable
     * @return
     */
    int getDISABLECountByDishIds(List<Long> dishIds, Integer disable);
    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
